<?php
    header("Content-type:text/html;charset=utf-8");
    require('./conn/mysql.php');

    $type = $_GET['type'];
    $goods_id = $_GET['goods_id'];
    $goods_name = $_GET['goods_name'];

    try{
        $sql = "select * from `goods`";
        if($type == 'cart'){
            $sql1 = "select count(*) from `goods`";
            $total = mysql::getOne($sql1);
            $num = mt_rand(1, $total);
            $sql = $sql." limit $num, 10"; //购物车页面随便给十条数据意思一下
        }
        if($goods_name){
            $sql = $sql." where goods_name like '%$goods_name%' ";
        }
        if($goods_id){
            $sql = $sql." where goods_id = $goods_id";
        }
        $res = mysql::getAll($sql);
        if(!$res) die(write(1, '无数据'));
        echo write(1, '获取成功', $res);
    }catch(\Throwable $t){
        echo write(0, ''.$t);
    }finally{
         mysql::close();
    }
    function write($code, $msg, $data=[]){
        $rd = array(
            'code' => $code,
            'msg' => $msg,
            'data' => $data,
        );
        return json_encode($rd, JSON_UNESCAPED_UNICODE);
    }
?>